# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007 by Infiscape Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import opendocument
import opendocument.core as core
import opendocument.xlink as xlink


class Event:
   UNKNOWN    = -1
   CHANGE     = 1
   FOCUS_IN   = 2
   FOCUS_OUT  = 3
   MOUSE_OVER = 4
   MOUSE_MOVE = 5
   MOUSE_DOWN = 6
   MOUSE_UP   = 7
   MOUSE_OUT  = 8
   RESET      = 9
   SUBMIT     = 10

   EVENT_MAP = {
      'dom:change'      : CHANGE,
      'dom:DOMFocusIn'  : FOCUS_IN,
      'dom:DOMFocusOut' : FOCUS_OUT,
      'dom:mouseover'   : MOUSE_OVER,
      'dom:mousemove'   : MOUSE_MOVE,
      'dom:mousedown'   : MOUSE_DOWN,
      'dom:mouseup'     : MOUSE_UP,
      'on-mouseout'     : MOUSE_OUT,
      'dom:reset'       : RESET,
      'dom:submit'      : SUBMIT,
   }

class EventListner(core.EventListener):
   def __init__(self, attrs):
      core.EventListener.__init__(self, attrs)
      self.setName(attrs.get('script:event-name', ''))

      self.langauge  = attrs.get('script:language', '')
      self.macroName = None
      self.macroLink = None

      if attrs.has_key('script:macro-name'):
         self.macroName = attrs.get('script:macro-name', '')
      else:
         self.macroLink = xlink.XLink(attrs)

   def getName(self):
      return self.name

   def setName(self, name):
      self.name = name.strip()

      if self.name in Event.EVENT_MAP.keys():
         self.eventID = Event.EVENT_MAP[name]
      else:
         self.eventID = Event.UNKNOWN

   def getEventID(self):
      return self.eventID

   def getLanguage(self):
      return self.language

   def getMacroName(self):
      return self.macroName

   def getMacroLink(self):
      return self.macroLink
